home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Examples / Draw / Sources / ShpTrakr.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  7.8 KB  |  288 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                ShpTrakr.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Author:                Henri Lamiraux
  7. //
  8. //    Copyright:    © 1993, 1995 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "ODFDraw.hpp"
  13.  
  14. #ifndef SHPTRAKR_H
  15. #include "ShpTrakr.h"
  16. #endif
  17.  
  18. #ifndef UTILS_H
  19. #include "Utils.h"
  20. #endif
  21.  
  22. #ifndef BASESHP_H
  23. #include "BaseShp.h"
  24. #endif
  25.  
  26. #ifndef BOUNDSHP_H
  27. #include "BoundShp.h"
  28. #endif
  29.  
  30. #ifndef LINESHP_H
  31. #include "LineShp.h"
  32. #endif
  33.  
  34. #ifndef OVALSHP_H
  35. #include "OvalShp.h"
  36. #endif
  37.  
  38. #ifndef RECTSHP_H
  39. #include "RectShp.h"
  40. #endif
  41.  
  42. #ifndef RRECTSHP_H
  43. #include "RRectShp.h"
  44. #endif
  45.  
  46. #ifndef TEXTSHP_H
  47. #include "TextShp.h"
  48. #endif
  49.  
  50. // ----- Part Layer -----
  51.  
  52. #ifndef FWUTIL_H
  53. #include "FWUtil.h"
  54. #endif
  55.  
  56. #ifndef FWVIEW_H
  57. #include "FWView.h"
  58. #endif
  59.  
  60. // ----- OS Layer -----
  61.  
  62. #ifndef FWRECSHP_H
  63. #include "FWRecShp.h"
  64. #endif
  65.  
  66. //========================================================================================
  67. // Runtime Information
  68. //========================================================================================
  69.  
  70. #ifdef FW_BUILD_MAC
  71. #pragma segment odfdraw
  72. #endif
  73.  
  74. //========================================================================================
  75. //    class CShapeTracker
  76. //========================================================================================
  77.  
  78. //----------------------------------------------------------------------------------------
  79. //    CShapeTracker::CShapeTracker
  80. //----------------------------------------------------------------------------------------
  81.  
  82. CShapeTracker::CShapeTracker(Environment* ev, FW_CView* view, ODFacet* facet, CBaseShape* theShape, FW_Boolean gridOn) :
  83.     FW_CTracker(ev, view, facet),
  84.     fShape(theShape),
  85.     fErase(FALSE),
  86.     fGridOn(gridOn)
  87. {
  88. }
  89.  
  90. //----------------------------------------------------------------------------------------
  91. //    CShapeTracker::~CShapeTracker
  92. //----------------------------------------------------------------------------------------
  93.  
  94. CShapeTracker::~CShapeTracker()
  95. {
  96. }
  97.  
  98. //----------------------------------------------------------------------------------------
  99. //    CShapeTracker::BeginTracking
  100. //----------------------------------------------------------------------------------------
  101.  
  102. FW_CPoint CShapeTracker::BeginTracking(Environment* ev, 
  103.                                     const FW_CPoint& anchorPoint)
  104. {
  105.     FW_CPoint point(anchorPoint);
  106.     ForceToGrid(ev, point);
  107.     return point;
  108. }
  109.  
  110. //----------------------------------------------------------------------------------------
  111. //    CShapeTracker::ContinueTracking
  112. //----------------------------------------------------------------------------------------
  113.  
  114. FW_CPoint CShapeTracker::ContinueTracking(Environment* ev,
  115.                                         const FW_CPoint& anchorPoint, 
  116.                                         const FW_CPoint& previousPoint, 
  117.                                         const FW_CPoint& currentPoint)
  118. {
  119.     FW_CPoint curLoc(currentPoint);
  120.     
  121.     ForceToGrid(ev, curLoc);
  122.     
  123.     if (previousPoint != curLoc)
  124.     {
  125.         FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
  126.         
  127.         if (fErase)
  128.             fShape->TrackFeedback(ev, GetFacet(ev), vc, anchorPoint, previousPoint, TRUE);
  129.         
  130.         fShape->TrackFeedback(ev, GetFacet(ev), vc, anchorPoint, curLoc, FALSE);
  131.         
  132.         fErase = TRUE;
  133.     }
  134.     
  135.     return curLoc;
  136. }
  137.  
  138. //----------------------------------------------------------------------------------------
  139. //    CShapeTracker::EndTracking
  140. //----------------------------------------------------------------------------------------
  141.  
  142. FW_Boolean CShapeTracker::EndTracking(Environment* ev,
  143.                                     const FW_CPoint& anchorPoint, 
  144.                                     const FW_CPoint& lastPoint)
  145. {
  146.     if (fErase)
  147.     {
  148.         FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
  149.         
  150.         fShape->TrackFeedback(ev, GetFacet(ev), vc, anchorPoint, lastPoint, TRUE);
  151.     }
  152.     
  153.     return anchorPoint != lastPoint;
  154. }
  155.  
  156. //----------------------------------------------------------------------------------------
  157. //    CShapeTracker::ForceToGrid
  158. //----------------------------------------------------------------------------------------
  159.  
  160. void CShapeTracker::ForceToGrid(Environment* ev, FW_CPoint& point)
  161. {
  162.     if (fGridOn)
  163.     {
  164.         point.x.SetInt((point.x.AsInt() + 5) / 8 * 8);
  165.         point.y.SetInt((point.y.AsInt() + 5) / 8 * 8);
  166.     }
  167. }
  168.  
  169. //========================================================================================
  170. //    class CResizeTracker
  171. //========================================================================================
  172.  
  173. //----------------------------------------------------------------------------------------
  174. //    CResizeTracker::CResizeTracker
  175. //----------------------------------------------------------------------------------------
  176.  
  177. CResizeTracker::CResizeTracker(Environment* ev,
  178.                                 FW_CView* view, ODFacet* facet, 
  179.                                 CBaseShape* theShape, short whichHandle,
  180.                                 const FW_PInk& resizeInk, const FW_PStyle& resizeStyle,
  181.                                 FW_Boolean gridOn) :
  182.     FW_CTracker(ev, view, facet),
  183.     fShape(theShape),
  184.     fWhichHandle(whichHandle),
  185.     fResizeInk(resizeInk),
  186.     fResizeStyle(resizeStyle),
  187.     fErase(FALSE),
  188.     fGridOn(gridOn)
  189. {
  190. }
  191.  
  192. //----------------------------------------------------------------------------------------
  193. //    CResizeTracker::~CResizeTracker
  194. //----------------------------------------------------------------------------------------
  195.  
  196. CResizeTracker::~CResizeTracker()
  197. {
  198. }
  199.  
  200. //----------------------------------------------------------------------------------------
  201. //    CResizeTracker::BeginTracking
  202. //----------------------------------------------------------------------------------------
  203.  
  204. FW_CPoint CResizeTracker::BeginTracking(Environment* ev, const FW_CPoint& anchorPoint)
  205. {
  206.     FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
  207.     
  208.     FW_CRectShape handle(FW_kZeroRect, FW_kFill);
  209.     handle.SetInk(FW_kInvertInk);
  210.     fShape->CalcHandle(fWhichHandle, &handle);
  211.     handle.Render(vc);    // redraw the handle
  212.  
  213.     FW_CPoint point(anchorPoint);
  214.     ForceToGrid(ev, point);
  215.     
  216.     FW_CPoint handleCenter;
  217.     fShape->GetHandleCenter(fWhichHandle, handleCenter);
  218.     fDelta = point - handleCenter;
  219.  
  220.     return handleCenter;
  221. }
  222.  
  223. //----------------------------------------------------------------------------------------
  224. //    CResizeTracker::ContinueTracking
  225. //----------------------------------------------------------------------------------------
  226.  
  227. FW_CPoint CResizeTracker::ContinueTracking(Environment* ev,
  228.                                             const FW_CPoint& anchorPoint, 
  229.                                             const FW_CPoint& previousPoint, 
  230.                                             const FW_CPoint& currentPoint)
  231. {
  232. FW_UNUSED(anchorPoint);
  233.  
  234.     // ----- Adjust for the size of the handle
  235.     FW_CPoint curLoc(currentPoint - fDelta);        
  236.     ForceToGrid(ev, curLoc);
  237.  
  238.     if (previousPoint != curLoc)
  239.     {
  240.         FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
  241.     
  242.         if (fErase)
  243.             fShape->ResizeFeedback(vc, fResizeInk, fResizeStyle, fWhichHandle, previousPoint);        // erase
  244.                 
  245.         fShape->ResizeFeedback(vc, fResizeInk, fResizeStyle, fWhichHandle, curLoc);            // draw
  246.         
  247.         fErase = TRUE;                
  248.     }
  249.     
  250.     return curLoc;
  251. }
  252.  
  253. //----------------------------------------------------------------------------------------
  254. //    CResizeTracker::EndTracking
  255. //----------------------------------------------------------------------------------------
  256.  
  257. FW_Boolean CResizeTracker::EndTracking(Environment* ev,
  258.                                     const FW_CPoint& anchorPoint, 
  259.                                     const FW_CPoint& lastPoint)
  260. {
  261. FW_UNUSED(anchorPoint);
  262.  
  263.     fLastLocation = lastPoint - fDelta;
  264.     ForceToGrid(ev, fLastLocation);
  265.     
  266.     if (fErase)
  267.     {
  268.         FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
  269.     
  270.         fShape->ResizeFeedback(vc, fResizeInk, fResizeStyle, fWhichHandle, fLastLocation);
  271.     }
  272.     
  273.     return anchorPoint != lastPoint;
  274. }
  275.  
  276. //----------------------------------------------------------------------------------------
  277. //    CResizeTracker::ForceToGrid
  278. //----------------------------------------------------------------------------------------
  279.  
  280. void CResizeTracker::ForceToGrid(Environment* ev, FW_CPoint& point)
  281. {
  282.     if (fGridOn)
  283.     {
  284.         point.x.SetInt((point.x.AsInt() + 5) / 8 * 8);
  285.         point.y.SetInt((point.y.AsInt() + 5) / 8 * 8);
  286.     }
  287. }
  288.